<?php

namespace app\models;

use Yii;
use yii\db\ActiveRecord;
use yii\data\Pagination;
use yii\db\Connection;
/**
 * This is the model class for table "tb_public".
 *
 * @property integer $id
 * @property string $title
 * @property string $content
 * @property string $pub_time
 */
class TbPublic extends ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'tb_public';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['pub_time'], 'safe'],
            [['title'], 'string', 'max' => 50],
            [['content'], 'string', 'max' => 200],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => Yii::t('app', 'ID'),
            'title' => Yii::t('app', 'Title'),
            'content' => Yii::t('app', 'Content'),
            'pub_time' => Yii::t('app', 'Pub Time'),
        ];
    }

    //查询5条最新公告
    public static function selecttopfives(){
        $sql="select * from tb_public  order by pub_time desc limit 5 ";
        $r=TbPublic::findBySql($sql)->all();
        return $r;
    }

    /**
     * 查询所有公告
     * @return \yii\db\ActiveQuery
     */
    public static function selectAll(){
        $public = self::find()->orderBy('pub_time desc')->all();
        return $public;
    }

    public static function selectId($id){
        return $public=self::find()->where(['id'=>$id])->one();
    }
}